$(function(){
	var pickerCreate = document.getElementById('regionA');
	  var pickerOpen = document.getElementById('open-picker');
//	  var pickerClose = document.getElementById('close-picker');
//	  var pickerSelect = document.getElementById('select-picker');
//	  var pickerRender = document.getElementById('render-picker');
	  var up, up1, up2,up3, animaed;
	  var up1Data;
	  var up2Data;
	  var up3Data;
	  var selectYes = document.getElementById('selectYes');
	  var selectClose = document.getElementById('selectClose');
	  var data = [];
	  $.ajax({
		  	type:"get",
			url:rootPath+"/address/selectAllRegion",
			dataType:"JSON",
			async: true,
			success:function(data1){
				data=data1.data;
				up1Data=data;
				up2Data=data[0].city;
				up3Data=up2Data[0].area;
			  selectYes.addEventListener('click', function() {
			    animaed.finish();
			    var address='';
			    var regionCodes='';
			    console.log($(".selected"))
			    $(".selected").each(function(i,item){
			    	if(i==0){
			    		$("#provinceCode").val(item.attributes.regioncode.nodeValue);
			    		$("#province").val(item.innerText);
			    	}else if(i==1){
			    		$("#cityCode").val(item.attributes.regioncode.nodeValue);
			    		$("#city").val(item.innerText);
			    	}else{
			    		$("#countyCode").val(item.attributes.regioncode.nodeValue);
			    		$("#county").val(item.innerText);
			    	}
			    	console.log(item)
			    	address+=item.innerText;
			    	regionCodes+=item.attributes.regioncode.nodeValue+',';
			    })
			    $("#region").text(address);
			    $("#region").attr('regionCode',regionCodes);
			
			    //if up1Data or up2Data is empty ,so use UPSelectRowIndexPath and UPThen
			
			    if (!up1Data && up) {
			      up.UPSelectRowIndexPath(1).UPThen(function(indexPath, value) {
			        console.log(value);
			      })
			    };
	  })

	  selectClose.addEventListener('click', function() {
	    animaed.finish();
	  })
	  if(up){
		  
	  }
	  pickerCreate.addEventListener('click', function() {
		  if(up){
			  animaed.start(); 
		  }else{
			  up = UIPickerView.createPickerView({
			      dataSource: data,
			      id: 'provincePicker',
			      constraintsId: 'wower',
			      kUP: {
			        kUPCELLHEIGHT: 26,
			        kUPFRICTION: 0.003
			      },
			      valueChange: function(data) {
			    	console.log(data);
			        up2Data = data.city;
			        up3Data=data.city[0].area;
			        up1 = UIPickerView.createPickerView({
			            dataSource: up2Data,
			            id: 'cityPicker',
			            constraintsId: 'wower1',
			            kUP: {
			              kUPCELLHEIGHT: 26,
			              kUPFRICTION: 0.003
			            },
			            valueChange: function(data) {
			              console.log(data);
			              up3Data = data.area;
				            up2 = UIPickerView.createPickerView({
				                dataSource: up3Data,
				                id: 'areaPicker',
				                constraintsId: 'wower2',
				                kUP: {
				                  kUPCELLHEIGHT: 26,
				                  kUPFRICTION: 0.003
				                },
				                valueChange: function(data) {
				                  console.log(data);
				                  up3Data = data;
				                }
				              });
			            }
			          });
			        up2 = UIPickerView.createPickerView({
			            dataSource: up3Data,
			            id: 'areaPicker',
			            constraintsId: 'wower2',
			            kUP: {
			              kUPCELLHEIGHT: 26,
			              kUPFRICTION: 0.003
			            },
			            valueChange: function(data) {
			              console.log(data);
			              up3Data = data;
			            }
			          });
			      }
			    });
			    up1 = UIPickerView.createPickerView({
			        dataSource: up2Data,
			        id: 'cityPicker',
			        constraintsId: 'wower1',
			        kUP: {
			          kUPCELLHEIGHT: 26,
			          kUPFRICTION: 0.003
			        },
			        valueChange: function(data) {
			          console.log(data);
			          up3Data = data.area;
			        }
			      });
			    up2 = UIPickerView.createPickerView({
			        dataSource: up3Data,
			        id: 'areaPicker',
			        constraintsId: 'wower2',
			        kUP: {
			          kUPCELLHEIGHT: 26,
			          kUPFRICTION: 0.003
			        },
			        valueChange: function(data) {
			          console.log(data);
			          up3Data = data;
			        }
			      });
			    
			    animaed = CAAnimation.createAnimation({
			      id: 'region-picker'
			    });
			    animaed.start();
		  }
	    
	  });

//	  pickerClose.addEventListener('click', function() {
//	    animaed.finish();
//	  });
//
//	  pickerOpen.addEventListener('click', function() {
//	    animaed.start();
//	  });
			}
	  })
})